<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for javascripts/dashboard/components/SliceAdder.jsx</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../../../prettify.css" />
    <link rel="stylesheet" href="../../../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../../../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../../../index.html">All files</a> / <a href="index.html">javascripts/dashboard/components</a> SliceAdder.jsx
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>0/48</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/26</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/9</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>0/46</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180</td><td class="line-coverage quiet"><span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js"><span class="cstat-no" title="statement not covered" >import $ from 'jquery';</span>
<span class="cstat-no" title="statement not covered" >import React, { PropTypes } from 'react';</span>
<span class="cstat-no" title="statement not covered" >import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';</span>
<span class="cstat-no" title="statement not covered" >import ModalTrigger from '../../components/ModalTrigger';</span>
<span class="cstat-no" title="statement not covered" >require('react-bootstrap-table/css/react-bootstrap-table.css');</span>
&nbsp;
c</span>onst propTypes = <span class="cstat-no" title="statement not covered" >{
  dashboard: PropTypes.object.isRequired,
  triggerNode: PropTypes.node.isRequired,
};
&nbsp;
class SliceAdder extends React.Component {
<span class="fstat-no" title="function not covered" >  constructor(</span>props) <span class="cstat-no" title="statement not covered" >{</span>
    super(props);
<span class="cstat-no" title="statement not covered" >    this.state = {</span>
      slices: [],
      slicesLoaded: false,
      selectionMap: {},
    };
&nbsp;
<span class="cstat-no" title="statement not covered" >    this.options = {</span>
      defaultSortOrder: 'desc',
      defaultSortName: 'modified',
      sizePerPage: 10,
    };
&nbsp;
<span class="cstat-no" title="statement not covered" >    this.addSlices = this.addSlices.bind(this);</span>
<span class="cstat-no" title="statement not covered" >    this.toggleSlice = this.toggleSlice.bind(this);</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >    this.selectRowProp = {</span>
      mode: 'checkbox',
      clickToSelect: true,
      onSelect: this.toggleSlice,
    };
  }
&nbsp;
  componentDidMount() <span class="cstat-no" title="statement not covered" >{</span>
    c</span>onst uri = <span class="cstat-no" title="statement not covered" >'/sliceaddview/api/read?_flt_0_created_by=' + this.props.dashboard.curUserId;
<span class="cstat-no" title="statement not covered" >    this.slicesRequest = $.ajax({</span>
      url: uri,
      type: 'GET',
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >      success: <span class="fstat-no" title="function not covered" >response =&gt; </span>{</span></span>
        // Prepare slice data for table
        c</span>onst slices = <span class="cstat-no" title="statement not covered" >response.result.map(<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >slice =&gt; ({</span></span>
          id: slice.id,
          sliceName: slice.slice_name,
          vizType: slice.viz_type,
          modified: slice.modified,
        }));
&nbsp;
<span class="cstat-no" title="statement not covered" >        this.setState({</span>
          slices,
          selectionMap: {},
          slicesLoaded: true,
        });
      },
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >      error: <span class="fstat-no" title="function not covered" >error =&gt; </span>{</span></span>
<span class="cstat-no" title="statement not covered" >        this.errored = true;</span>
<span class="cstat-no" title="statement not covered" >        this.setState({</span>
          errorMsg: this.props.dashboard.getAjaxErrorMsg(error),
        });
      },
    });
  }
&nbsp;
  componentWillUnmount() {
<span class="cstat-no" title="statement not covered" >    this.slicesRequest.abort();</span>
  }
&nbsp;
  addSlices() {
<span class="cstat-no" title="statement not covered" >    this.props.dashboard.addSlicesToDashboard(Object.keys(this.state.selectionMap));</span>
  }
&nbsp;
  toggleSlice(slice) {
    c</span>onst selectionMap = <span class="cstat-no" title="statement not covered" >Object.assign({}, this.state.selectionMap);
<span class="cstat-no" title="statement not covered" >    selectionMap[slice.id] = !selectionMap[slice.id];</span>
<span class="cstat-no" title="statement not covered" >    this.setState({ selectionMap });</span>
  }
&nbsp;
  modifiedDateComparator(a, b, order) {
<span class="cstat-no" title="statement not covered" >    if (order === 'desc') {</span>
<span class="cstat-no" title="statement not covered" >      if (a.changed_on &gt; b.changed_on) {</span>
<span class="cstat-no" title="statement not covered" >        return -1;</span>
      } else <span class="cstat-no" title="statement not covered" >if (a.changed_on &lt; b.changed_on) {</span>
<span class="cstat-no" title="statement not covered" >        return 1;</span>
      }
<span class="cstat-no" title="statement not covered" >      return 0;</span>
    }
&nbsp;
<span class="cstat-no" title="statement not covered" >    if (a.changed_on &lt; b.changed_on) {</span>
<span class="cstat-no" title="statement not covered" >      return -1;</span>
    } else <span class="cstat-no" title="statement not covered" >if (a.changed_on &gt; b.changed_on) {</span>
<span class="cstat-no" title="statement not covered" >      return 1;</span>
    }
<span class="cstat-no" title="statement not covered" >    return 0;</span>
  }
&nbsp;
  render() {
    c</span>onst hideLoad = <span class="cstat-no" title="statement not covered" >this.state.slicesLoaded || this.errored;
    l</span>et enableAddSlice = <span class="cstat-no" title="statement not covered" >this.state.selectionMap &amp;&amp; Object.keys(this.state.selectionMap);
<span class="cstat-no" title="statement not covered" >    if (enableAddSlice) {</span>
<span class="cstat-no" title="statement not covered" >      enableAddSlice = enableAddSlice.some(<span class="fstat-no" title="function not covered" >function (</span>key) {</span>
<span class="cstat-no" title="statement not covered" >        return this.state.selectionMap[key];</span>
      }, this);
    }
    const modalContent = (
<span class="cstat-no" title="statement not covered" >      &lt;div&gt;</span>
        &lt;img
          src="/static/assets/images/loading.gif"
          className={'loading ' + (hideLoad ? 'hidden' : '')}
          alt={hideLoad ? '' : 'loading'}
        /&gt;
        &lt;div className={this.errored ? '' : 'hidden'}&gt;
          {this.state.errorMsg}
        &lt;/div&gt;
        &lt;div className={this.state.slicesLoaded ? '' : 'hidden'}&gt;
          &lt;BootstrapTable
            ref="table"
            data={this.state.slices}
            selectRow={this.selectRowProp}
            options={this.options}
            hover
            search
            pagination
            condensed
            height="auto"
          &gt;
            &lt;TableHeaderColumn
              dataField="sliceName"
              isKey
              dataSort
            &gt;
              Name
            &lt;/TableHeaderColumn&gt;
            &lt;TableHeaderColumn
              dataField="vizType"
              dataSort
            &gt;
              Viz
            &lt;/TableHeaderColumn&gt;
            &lt;TableHeaderColumn
              dataField="modified"
              dataSort
              sortFunc={this.modifiedDateComparator}
              // Will cause react-bootstrap-table to interpret the HTML returned
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >              dataFormat={<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >modified =&gt; modified}</span></span></span></span>
            &gt;
              Modified
            &lt;/TableHeaderColumn&gt;
          &lt;/BootstrapTable&gt;
          &lt;button
            type="button"
            className="btn btn-default"
            data-dismiss="modal"
            onClick={this.addSlices}
            disabled={!enableAddSlice}
          &gt;
            Add Slices
          &lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    );
&nbsp;
<span class="cstat-no" title="statement not covered" >    return (</span>
      &lt;ModalTrigger
        triggerNode={this.props.triggerNode}
        tooltip="Add a new slice to the dashboard"
        isButton
        modalBody={modalContent}
        bsSize="large"
        modalTitle="Add Slices to Dashboard"
      /&gt;
    );
  }
}
&nbsp;
<span class="cstat-no" title="statement not covered" >SliceAdder.propTypes = propTypes;</span>
&nbsp;
export default SliceAdder;
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Apr 11 2017 20:15:55 GMT-0700 (PDT)
</div>
</div>
<script src="../../../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../../../sorter.js"></script>
</body>
</html>
